function debounce(fn, timer) {
  let t = null

  return function () {
    let _arg = arguments
    if(t) {
      clearTimeout(t)
      t = null
    }

    t = setTimeout(function () {
      fn.apply(this, _arg)
      t = null
    }, timer)
  }
}

function throttle(fn, timer) {
  let t = null

  return function () {
    let _arg = arguments
    if(t) {
      return
    }

    t = setTimeout(function () {
      fn.apply(this, _arg)
      clearTimeout(t)
      t = null
    }, timer)
  }
}